import os
import requests
from bs4 import BeautifulSoup
def download(MD5,ID):
    url = f"http://10.102.0.89:8080/api/file/download/{MD5}"
    save_path = f"D:/软件打包/Juno-win32.win32.x86_64/Juno-win32.win32.x86_64/{ID}.HTML"  # 指定的保存路径
    if os.path.exists(save_path):
        print("文件已存在，无需下载")
    else:
        response = requests.get(url)
        response.encoding='utf-8'
        html=response.text
        soup=BeautifulSoup(html,'html.parser')
        if response.status_code == 200:
            # 确保保存目录存在
            os.makedirs(os.path.dirname(save_path), exist_ok=True)
            with open(save_path, "wb") as f:
                f.write(response.content)
            print("文件下载成功")
            if soup.text == """{"code":404,"msg":"业务异常：文件不存在,cause:文件不存在","data":null}""":
                return 0
            else:
                return 1
        else:
            print("文件下载失败，状态码:", response.status_code)


if  __name__ == "__main__":
    download('E922F65810401F8122250FD546B8257C','746569103037')